<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
    <script>
        // 1）新增的API
        /* const person = {
            name: "jack",
            age: 21,
            language: ['java', 'js', 'css']
        };
        console.log(Object.keys(person));
        console.log(Object.values(person));
        console.log(Object.entries(person)); */

        /* const target = {a:1};
        const source1 = {b:2};
        const source2 = {c:3};
        // Object.assign方法的第一个参数是目标对象，后面的参数都是源对象
        Object.assign(target, source1, source2);
        console.log(target); */

        // 2）声明对象简写
        /* const age = 23;
        const name = "张三";
        // 传统
        const person1 = {age: age, name: name};
        console.log(person1);

        // ES6：属性名和属性值变量名一样时，可以省略掉属性名
        const person2 = {age, name};
        console.log(person2); */

        // 3）对象的函数属性简写
        /* let person = {
            name: "jack",
            // 以前（这里的this是person）
            eat: function(food) {
                console.log(this.name + "在吃" + food);
            },
            // 箭头函数版（这里的this是window对象，而不是person）
            eat2:food=>console.log(person.name + "在吃" + food),
            // 简写版
            eat3(food) {
                console.log(this.name + "在吃" + food);
            }
        };

        person.eat3("apple"); */

        // 4）对象拓展运算符
        // 1.拷贝对象（浅拷贝），课程资料写的是深拷贝，里面弄错了
        /* let person1 = {name:"Amy", age:15, obj:{a:11,b:22}};
        let someone = {...person1};
        console.log(someone); */

        // 2.合并对象
        let ageObj = {age:15};
        let nameObj = {name:"Amy"};
        let person2 = {...ageObj, ...nameObj}; // 如果两个对象的字段名重复，后面对象字段值会覆盖前面对象的字段值
        console.log(person2); // {age:15,name:"Amy"}
    </script>
</body>
</html>